import { c as defineEventHandler, e as sendError, f as createError } from '../../_/nitro.mjs';
import mysql from 'mysql2/promise';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';

let connection;
(async () => {
  connection = await mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "123456",
    database: "nuxt-data"
  });
})();

const user = defineEventHandler(async (event) => {
  try {
    const [data] = await connection.query("select id,name,age,create_by,create_time,update_by,update_time from sys_user");
    return {
      code: 200,
      message: "success",
      data
    };
  } catch (error) {
    console.error("MySQL error: ", error);
    return sendError(event, createError({ statusCode: 500, statusMessage: "Database error" }));
  }
});

export { user as default };
//# sourceMappingURL=user.mjs.map
